import 'package:flutter/cupertino.dart';
import 'package:mtf/app/widget/HcSpace.dart';

class HcIconText extends StatelessWidget {
  //文字
  final Widget? label;

  //icon
  final Widget? icon;

  //间隔
  final double spacing;

  //排列
  final Axis direction;

  //是否翻转
  final bool reverse;

  //主轴对齐方式
  final MainAxisAlignment mainAxisAlignment;

  //次轴对齐方式
  final CrossAxisAlignment crossAxisAlignment;

  //主轴大小
  final MainAxisSize mainAxisSize;

  const HcIconText({
    super.key,
    this.label,
    this.icon,
    this.spacing = 8.0,
    this.direction = Axis.horizontal,
    this.reverse = false,
    this.crossAxisAlignment = CrossAxisAlignment.center,
    this.mainAxisAlignment = MainAxisAlignment.center,
    this.mainAxisSize = MainAxisSize.min,
  });

  @override
  Widget build(BuildContext context) {
    List<Widget> list = List.empty(growable: true);
    if (icon != null) {
      list.add(icon!);
    }
    if (icon != null && label != null && (spacing != 0)) {
      list.add(HcSpace(
        width: spacing,
        height: spacing,
      ));
    }
    if (label != null) {
      list.add(label!);
    }
    if (list.isEmpty) {
      list.add(const SizedBox());
    }

    return list.length == 1
        ? list.first
        : direction == Axis.horizontal
            ? Row(
                mainAxisSize: mainAxisSize,
                crossAxisAlignment: crossAxisAlignment,
                mainAxisAlignment: mainAxisAlignment,
                textDirection: reverse ? TextDirection.rtl : TextDirection.ltr,
                children: list,
              )
            : Column(
                mainAxisSize: mainAxisSize,
                mainAxisAlignment: mainAxisAlignment,
                verticalDirection:
                    reverse ? VerticalDirection.up : VerticalDirection.down,
                crossAxisAlignment: crossAxisAlignment,
                children: list,
              );
  }
}
